`
Listing 2-36
Printing line ranges in a file
When you pass sed the -i argument, it will make the changes to the file
itself rather than create a modified copy (Listing 2-37).
sed -i '1d' log.txt
Listing 2-37
Making changes to the original file
This rich utility can do a whole lot more. Use the man sed command to find
additional ways to use sed.
Job Control
As you become proficient in bash, you’ll start to build complex scripts that
take an hour to complete or must run continuously. Not all scripts need to execute
in the foreground, blocking execution of other things. Instead, you may want to
run certain scripts as background jobs, either because they take a while to
complete or because their runtime output isn’t interesting and you care only about
the end result.
Commands that you run in a terminal occupy that terminal until the command
is finished. These commands are considered foreground jobs. In Chapter 1, we
used the ampersand character (&) to send a command to the background. This
command then becomes a background job that allows us to unblock the execution
of other commands.
Managing Background and Foreground Jobs
To practice working with foreground and background jobs, let’s run a
command directly in the terminal and send it to the background:
$ sleep 100 &
Notice that we can continue working on the terminal while this sleep
command runs for 100 seconds. You can verify the spawned process is running by
using the ps command:
$ ps -ef | grep sleep
user 1827 1752 cons0 19:02:29 /usr/bin/sleep
Now that this job is in the background, we can use the jobs command to see
what jobs are currently running (Listing 2-38).
$ jobs
[1]+ Running sleep 100 &
Listing 2-38
Listing jobs
The output shows that the sleep command is in Running state and that its
job ID is 1.
Black Hat Bash (Early Access) © 2023 by Dolev Farhi and Nick Aleks